package entry75;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.junit.Test;

public class StringListSave {
	@Test
	public void testSave() throws FileNotFoundException, IOException,
			ClassNotFoundException {
		StringList list = new StringList();

		for (int i = 0; i < 1500; i++) {
			list.add("1111111111");
		}

		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
				"./string.ser"));
		oos.writeObject(list);

		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
				"./string.ser"));
		StringList list2 = (StringList) ois.readObject();
		ois.close();

		int n = list.size();
		assertThat(list.size(), is(list2.size()));
		for (int i = 0; i < n; i++) {
			assertThat(list.get(i), is(list2.get(i)));
		}

		oos.close();
	}

	@Test
	public void testSaveLight() throws FileNotFoundException, IOException,
			ClassNotFoundException {
		LightStringList list = new LightStringList();

		for (int i = 0; i < 1500; i++) {
			list.add("1111111111");
		}

		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
				"./string_light.ser"));
		oos.writeObject(list);
		oos.close();

		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
				"./string_light.ser"));
		LightStringList list2 = (LightStringList) ois.readObject();
		ois.close();

		int n = list.size();
		assertThat(list.size(), is(list2.size()));
		for (int i = 0; i < n; i++) {
			assertThat(list.get(i), is(list2.get(i)));
		}
	}
}
